<?php
/*
 * @Author: CHINAKAIYUAN<sunkaiyuan@namenode.cn>
 * @Date: 2022-02-03 00:33:05
 * @LastEditTime: 2022-08-28 11:09:06
 * @LastEditors: CHINAKAIYUAN
 * @Description: 
 */

namespace App\Models;

use App\Traits\SoftDeletesTrait;
use App\Traits\AttachmentTrait;
use App\Traits\AutoCodeTrait;

class PurchaseApply extends BaseModel
{
    use SoftDeletesTrait;
    use AutoCodeTrait;
    use AttachmentTrait;
    public $timestamps = true;
    public $table = "sys_purchase_apply";
    protected $guarded = [];
    //附件
    public $attachmentkey = "code";

    /**
     * 标识
     *
     * @var string
     */
    protected $ACSign = 'PURCHASE_APPLY';

    /**
     * 编号所用的字段
     *
     * @var string
     */
    protected $ACCode = 'code';
    public function department()
    {
        return $this->belongsTo(Department::class);
    }
    public function status()
    {
        return  $this->belongsTo(Dic::class, "status_id", "key")->where(function ($q) {
            $q->where("code", 'status_name');
        });
    }
    public function details()
    {
        return $this->hasMany(PurchaseApplyDetails::class, "main_id");
    }
}
